package exanination;
import java.util.Scanner;
/*
*对10个数进行排序（键盘随机录入10个数）
*冒泡排序
* */
public class sort {
    public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        int[] numbers = new int[10];
        System.out.println("请输入10个数：");
        for (int i = 0; i < numbers.length; i++) {
            numbers[i]= sca.nextInt();
        }
        sca.close();
        bubbleSort(numbers);
        System.out.println("排序后的数组为：");
        for (int num:numbers){
            System.out.print(num+"\t");
        }
    }
    public static void bubbleSort(int[] arr){
        int m = arr.length;
        for (int i = 0; i < m - 1; i++) {
            for (int j = 0; j < m - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}
